<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="${column.comments}" prop="proposalNo">
      <el-input v-model="dataForm.proposalNo" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="insuranceNo">
      <el-input v-model="dataForm.insuranceNo" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="productId">
      <el-input v-model="dataForm.productId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="productName">
      <el-input v-model="dataForm.productName" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="caseId">
      <el-input v-model="dataForm.caseId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="caseName">
      <el-input v-model="dataForm.caseName" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="totalPrice">
      <el-input v-model="dataForm.totalPrice" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="startDate">
      <el-input v-model="dataForm.startDate" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="endDate">
      <el-input v-model="dataForm.endDate" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createPersonName">
      <el-input v-model="dataForm.createPersonName" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createPersonId">
      <el-input v-model="dataForm.createPersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="updatepersonId">
      <el-input v-model="dataForm.updatepersonId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="insuranceCompany">
      <el-input v-model="dataForm.insuranceCompany" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="onlineUrl">
      <el-input v-model="dataForm.onlineUrl" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="excelLogId">
      <el-input v-model="dataForm.excelLogId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="appId">
      <el-input v-model="dataForm.appId" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="state">
      <el-input v-model="dataForm.state" placeholder="${column.comments}"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          proposalId: 0,
          proposalNo: '',
          insuranceNo: '',
          productId: '',
          productName: '',
          caseId: '',
          caseName: '',
          totalPrice: '',
          startDate: '',
          endDate: '',
          createTime: '',
          createPersonName: '',
          createPersonId: '',
          updateTime: '',
          updatepersonId: '',
          insuranceCompany: '',
          onlineUrl: '',
          excelLogId: '',
          appId: '',
          state: ''
        },
        dataRule: {
          proposalNo: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          insuranceNo: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          productId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          productName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          caseId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          caseName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          totalPrice: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          startDate: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          endDate: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createPersonName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createPersonId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          updatepersonId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          insuranceCompany: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          onlineUrl: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          excelLogId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          appId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.proposalId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.proposalId) {
            this.$http({
              url: this.$http.adornUrl(`/proposal/proposal/info/${this.dataForm.proposalId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.proposalNo = data.proposal.proposalNo
                this.dataForm.insuranceNo = data.proposal.insuranceNo
                this.dataForm.productId = data.proposal.productId
                this.dataForm.productName = data.proposal.productName
                this.dataForm.caseId = data.proposal.caseId
                this.dataForm.caseName = data.proposal.caseName
                this.dataForm.totalPrice = data.proposal.totalPrice
                this.dataForm.startDate = data.proposal.startDate
                this.dataForm.endDate = data.proposal.endDate
                this.dataForm.createTime = data.proposal.createTime
                this.dataForm.createPersonName = data.proposal.createPersonName
                this.dataForm.createPersonId = data.proposal.createPersonId
                this.dataForm.updateTime = data.proposal.updateTime
                this.dataForm.updatepersonId = data.proposal.updatepersonId
                this.dataForm.insuranceCompany = data.proposal.insuranceCompany
                this.dataForm.onlineUrl = data.proposal.onlineUrl
                this.dataForm.excelLogId = data.proposal.excelLogId
                this.dataForm.appId = data.proposal.appId
                this.dataForm.state = data.proposal.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/proposal/proposal/${!this.dataForm.proposalId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'proposalId': this.dataForm.proposalId || undefined,
                'proposalNo': this.dataForm.proposalNo,
                'insuranceNo': this.dataForm.insuranceNo,
                'productId': this.dataForm.productId,
                'productName': this.dataForm.productName,
                'caseId': this.dataForm.caseId,
                'caseName': this.dataForm.caseName,
                'totalPrice': this.dataForm.totalPrice,
                'startDate': this.dataForm.startDate,
                'endDate': this.dataForm.endDate,
                'createTime': this.dataForm.createTime,
                'createPersonName': this.dataForm.createPersonName,
                'createPersonId': this.dataForm.createPersonId,
                'updateTime': this.dataForm.updateTime,
                'updatepersonId': this.dataForm.updatepersonId,
                'insuranceCompany': this.dataForm.insuranceCompany,
                'onlineUrl': this.dataForm.onlineUrl,
                'excelLogId': this.dataForm.excelLogId,
                'appId': this.dataForm.appId,
                'state': this.dataForm.state
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
